package com.sky.mapper.admin;

import com.sky.dto.SetmealPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.pojo.Setmeal;
import com.sky.pojo.SetmealDish;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description setMealMapper
 * @Author luohai
 * @Date 2024-10-04
 */
@Mapper
public interface setMealMapper {

    /**
     * 新增套餐
     * @param setmeal
     * @return
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into setmeal(category_id, name, price, description, image, create_time, update_time, create_user, update_user, make_time) VALUES (#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},#{makeTime})")
    void addSetMeal(Setmeal setmeal);

    /**
     * 新增套餐菜品
     * @param setmealDishes
     */
    void addsetmealDishes(List<SetmealDish> setmealDishes);


    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    List<SetmealVO> setMealPaginationQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    void deleteSetMealById(List<Long> ids);

    /**
     * 根据Id查询套餐状态
     * @param id
     * @return
     */
    Integer selectStatusById(Long id);

    /**
     * 根据ID查询套餐（数据回显）
     * @param setmealId
     * @return
     */
    SetmealVO selectSetMealById(Long setmealId);

    /**
     * 根据ID修改套餐
     * @param setmeal
     * @return
     */
    @Options(keyProperty = "id",useGeneratedKeys = true)
    void modifySetMealById(Setmeal setmeal);

    /**
     * 根据ID删除套餐菜品
     * @param id
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{id}")
    void deleteSetMealDishesById(Long id);

    /**
     * 根据ID添加套餐菜品
     * @param setmealDishes
     */
    void addSetMealDishsById(List<SetmealDish> setmealDishes);

    /**
     * 起售停售套餐
     * @param status
     * @param id
     * @return
     */
    void startOrStop(Integer status, Long id);

    /**
     * 批量删除套餐菜品
     * @param ids
     */
    void deleteSetMealDishesById1(List<Long> ids);

    //根据setmeal_id查询dish_id
    @Select("select dish_id from setmeal_dish where setmeal_id = #{id}")
    List<Long> searchDishId(Long id);

    //根据dish_id 查询 菜品状态
    List<Dish> searchDishStatus(List<Long> dishId);

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    List<Setmeal> list(Long categoryId);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
